import java.util.Stack;

public class demo3 {
    public String removeDuplicates(String s) {
        Stack<Character> stack=new Stack<Character>();
        for(int i=0;i<s.length();i++) {
            if(stack.isEmpty())stack.add(s.charAt(i));
            if(s.charAt(i)!=stack.peek()) {
                stack.add(s.charAt(i));
            }else {
                if(!stack.isEmpty())stack.pop();
            }
        }
        StringBuilder stringBuilder=new StringBuilder();
        while(!stack.isEmpty()) {
            stringBuilder.append(stack.pop());
        }
        return stringBuilder.toString();
    }
}
